package com.lzx.reggie.utils
import com.aliyuncs.DefaultAcsClient
import com.aliyuncs.IAcsClient
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest
import com.aliyuncs.exceptions.ClientException
import com.aliyuncs.profile.DefaultProfile

/**
 * 短信发送工具类
 */
object SMSUtils {
    /**
     * 发送短信
     * @param signName 签名
     * @param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param 参数
     */
    fun sendMessage(signName: String?, templateCode: String?, phoneNumbers: String?, param: String) {
        val profile: DefaultProfile = DefaultProfile.getProfile("cn-hangzhou", "", "")
        val client: IAcsClient = DefaultAcsClient(profile)
        val request = SendSmsRequest()
        request.sysRegionId = "cn-hangzhou"
        request.phoneNumbers = phoneNumbers
        request.signName = signName
        request.templateCode = templateCode
        request.templateParam = "{\"code\":\"$param\"}"
        try {
            val response = client.getAcsResponse(request)
            println("短信发送成功")
        } catch (e: ClientException) {
            e.printStackTrace()
        }
    }
}
